package fhedu;


import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

public class Cell extends GameCanvas{
    public int mauvien, maunen, mauchu;
    public String text;
    public int cao, rong;
    public Image cell;
    public int IsImage=0;
    public int canle=1;//0:trái, 1: giữa, 2:phải
    public Cell()
    {
     super(false);   
    }
    public Cell(String text, int rong, int cao, int mauchu, int mauvien, int maunen)
    {
        super(false);
        this.text=text;
        this.rong=rong;
        this.cao=cao;
        this.mauchu=mauchu;
        this.mauvien=mauvien;
        this.maunen=maunen;
    }

    public void VeCell(Graphics g, int x, int y)
    {
        
        cell= Image.createImage(rong,cao);
        Graphics gcell;
        
        gcell=cell.getGraphics();
        //g.setFont(font);
        gcell.setFont(g.getFont());
        gcell.setColor(maunen);
        gcell.fillRect(0, 0, rong-1, cao-1);
        gcell.setColor(mauvien);
        gcell.drawRect(0, 0, rong-1, cao-1);
        gcell.setColor(mauchu);
        
        //int le;
        if(IsImage==0)
        {
        if(canle==0)gcell.drawString(text, 2, 2, Graphics.TOP|Graphics.LEFT);
        else
            if(canle==1)gcell.drawString(text, rong/2, 2, Graphics.TOP|Graphics.HCENTER);
            else
                gcell.drawString(text, rong-2, 2, Graphics.TOP|Graphics.RIGHT);
        }
        else
        {
            try{
                    Image img=Image.createImage(text);
                    if(canle==0)gcell.drawImage(img, 1, 1, Graphics.TOP|Graphics.LEFT);
                    else
                    if(canle==1)gcell.drawImage(img, rong/2, 1, Graphics.TOP|Graphics.HCENTER);
                    else
                        gcell.drawImage(img, rong-1, 1, Graphics.TOP|Graphics.RIGHT);
                
            }catch(Exception e){};
        }
        
       // gcell.drawString(text, rong/2, 2, Graphics.TOP|Graphics.HCENTER);
        g.drawImage(cell, x, y, Graphics.TOP|Graphics.LEFT);
        flushGraphics(); 
        
        
    }
    
    public void setAtt(String text, int rong, int cao, int mauchu, int mauvien, int maunen)
    {
        this.text=text;
        this.rong=rong;
        this.cao=cao;
        this.mauchu=mauchu;
        this.mauvien=mauvien;
        this.maunen=maunen;
    }
}
